package com.xywl.escort.adapter.provider;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.xywl.escort.R;
import com.xywl.escort.adapter.HomeRvAdapter;
import com.xywl.escort.adapter.ProjectAdapter;
import com.xywl.escort.bean.MessageEvent;
import com.xywl.escort.bean.ProjectListResp;
import com.xywl.escort.entity.NormalMultipleEntity;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import static com.xywl.escort.common.Constant.EventType.EVENT_MAIN_TYPE;

@ItemProviderTag(
        viewType = HomeRvAdapter.TYPE_RECYCLE,
        layout = R.layout.view_project
)
public class RecycleItemProvider extends BaseItemProvider<NormalMultipleEntity, BaseViewHolder> {

    @Override
    public void convert(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        RecyclerView recyclerView = helper.getView(R.id.recycler_farm);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);

        final List<ProjectListResp.DataBean.ListBean> list = data.mProjectData;
        ProjectAdapter adapter = new ProjectAdapter(R.layout.item_project, list);
        recyclerView.setAdapter(adapter);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String projectId = list.get(position).id;
                String title = list.get(position).name;
                ARouter.getInstance().build("/xy/project/detail")
                        .withString("projectId", projectId)
                        .withString("title", title)
                        .navigation();
            }
        });

        TextView textView = helper.getView(R.id.tv_adoption_more);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new MessageEvent(EVENT_MAIN_TYPE, "farm"));
            }
        });
    }

    @Override
    public void onClick(BaseViewHolder helper, NormalMultipleEntity data, int position) {
    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        return false;
    }
}
